package com.boss.salary.service.impl;

import com.boss.salary.entity.HomesMenuTree;
import com.boss.salary.service.IHomeMenuTreeService;
import com.boss.sys.config.CseCommonConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

/**
 * @author hao
 * @date 2023/4/13 17:10
 */
@Service
public class HomeMenuTreeServiceImpl implements IHomeMenuTreeService {

    @Autowired
    private CseCommonConfiguration urlConfiguration;
    @Autowired
    private RestTemplate restTemplate;
    private  static String MENUTREE="/v1/menutreeinfo";
    private  static String APPGUID="salary";
    @Override
    public List<HomesMenuTree> getMenuTree(String tokenid) {
        String url=urlConfiguration.getPermservice()+MENUTREE;
        HttpHeaders headers = new HttpHeaders();
        headers.add("tokenid",tokenid);
        headers.add("appguid",APPGUID);
        HttpEntity<HomesMenuTree> requestEntity = new HttpEntity<>(null, headers);
        ResponseEntity<HomesMenuTree[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, HomesMenuTree[].class);

        return Arrays.asList(responseEntity.getBody());
    }
}
